package com.example.ad;

import lombok.RequiredArgsConstructor;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.Topic;

/**
 * ActiveController
 *
 * @author wangrui
 * @date 2022/1/25 10:39
 */
@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class ActiveController {
    private final JmsMessagingTemplate messagingTemplate;

    private final Topic topic;

    private final Queue queue;

    @GetMapping("sendQueue")
    public String sendQueue(String str) {
        send(queue, str);
        return "success";
    }

    @GetMapping("sendTopic")
    public String sendTopic(String str) {
        send(topic, str);
        return "success";
    }

    private void send(Destination destination, final String msg) {
        messagingTemplate.convertAndSend(destination, msg);
    }
}
